package com.moxiao.yfjh.module.blind.common;

import com.alibaba.fastjson.JSON;
import org.apache.commons.lang3.StringUtils;
import org.apache.http.HttpResponse;
import org.apache.http.util.EntityUtils;
import org.springframework.stereotype.Component;

import java.util.HashMap;
import java.util.Map;

/**
 * @version 1.0
 * @Author zhk
 * @Date 2024/2/18 13:46
 **/
@Component
public class IdentityAuthUtils {


    public static String identification(String name, String idCard) {
        String bizCode = "3";
        String host = "https://id2meta.market.alicloudapi.com";
        String path = "/id2meta";
        String method = "GET";
        String appcode = "97ac64e50ce242a791c05eff848546d6";
        Map<String, String> headers = new HashMap<String, String>();
        //最后在header中的格式(中间是英⽂空格)为Authorization:APPCODE
//            83359f d73fe94948385f570e3c139105
        headers.put("Authorization", "APPCODE " + appcode);
        Map<String, String> querys = new HashMap<String, String>();
        querys.put("identifyNum", idCard);
//            querys.put("identifyNumMd5", "identifyNumMd5");
        querys.put("userName", name);
//        querys.put("userNameMd5", "userNameMd5");
        try {
            /**
             * 重要提示如下:
             * HttpUtils请从
             * https://github.com/aliyun/api-gateway-demo-signjava/blob/master/src/main/java/com/aliyun/api/gateway/demo/util/HttpUtils
             .java
             * 下载
             *
             * 相应的依赖请参照
             * https://github.com/aliyun/api-gateway-demo-signjava/blob/master/pom.xml
             */
            HttpResponse response = HttpUtils.doGet(host, path, method,
                    headers, querys);
            String s = EntityUtils.toString(response.getEntity());
            // 获取验证值
            com.alibaba.fastjson.JSONObject createJsonObject = JSON.parseObject(s.toString());
            String data = createJsonObject.getString("data");
            if (StringUtils.isNotEmpty(data)) {
                com.alibaba.fastjson.JSONObject createJsonObject1 = JSON.parseObject(data.toString());
                bizCode = createJsonObject1.getString("bizCode");
            }
            return bizCode;
        } catch (Exception e) {
            throw new RuntimeException(e);
        } finally {
            return bizCode;
        }
    }


    public static void main(String[] args) {
        String 张学利 = identification("张学利", "372330199911257271");
    }

}
